/*
 * @copyright 2011 Gerald Jacobson
 * @license GNU General Public License
 * 
 * This file is part of GameTimer.
 *
 * GameTimer is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * GameTimer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GameTimer. If not, see <http://www.gnu.org/licenses/>.
 */
package org.amphiption.gametimer.util;

import java.util.Comparator;

import org.amphiption.gametimer.screen.component.PlayerComponent;

import android.graphics.PointF;

import com.amphiprion.prototype.util.DrawUtil;

/**
 * @author Amphiprion
 * 
 */
public class GameComponentAngleComparator implements Comparator<PlayerComponent> {
	private float centerX;
	private float centerY;

	public GameComponentAngleComparator(float centerX, float centerY) {
		this.centerX = centerX;
		this.centerY = centerY;
	}

	@Override
	public int compare(PlayerComponent pc1, PlayerComponent pc2) {
		float angle1 = DrawUtil.getAngle(new PointF(pc1.getX(), pc1.getY()), new PointF(centerX, centerY));
		if (angle1 < 0) {
			angle1 = 360 + angle1;
		}
		float angle2 = DrawUtil.getAngle(new PointF(pc2.getX(), pc2.getY()), new PointF(centerX, centerY));
		if (angle2 < 0) {
			angle2 = 360 + angle2;
		}
		if (angle1 < angle2) {
			return -1;
		} else if (angle1 > angle2) {
			return 1;
		} else {
			return 0;
		}
	}

}
